import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:workmate/plugins/dialog/index.dart';
import 'package:workmate/provider/global.dart';

/// 全局弹窗提示
class Layer {
  late FToast? ftoast;
  Layer() {
    ftoast = null;
  }

  init() {
    if (ftoast == null) {
      ftoast = FToast();
      ftoast?.init(APP.navigatorKey.currentState!.context);
    }
  }

  dialog(
    BuildContext context, {
    required Widget child,
  }) {
    return CustomDialog(context,
            body: DialogBody(
                content: child,
                iconType: IconTypes.success,
                padding: const EdgeInsets.all(30),
                decoration: const BoxDecoration(
                  color: Colors.white60,
                )),
            width: 300,
            backgroundColor: Colors.black)
        .show();
  }

  loading() {}

  message(String msg, {Icon? icon, ToastGravity? gravity}) {
    init();
    List<Widget> list = [];
    if (icon == null) {
      list.add(Padding(padding: const EdgeInsets.only(right: 4), child: icon
          // const Icon(
          //   Icons.check,
          //   size: 16,
          //   color: Colors.white,
          // )
          ));
    }
    list.add(Text(
      msg,
      style: const TextStyle(color: Colors.white, fontSize: 12, height: 1.25),
    ));
    ftoast!.showToast(
        child: Container(
          padding: const EdgeInsets.symmetric(horizontal: 12.0, vertical: 8.0),
          decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(24.0),
            color: Colors.black87,
          ),
          child: Row(
            mainAxisSize: MainAxisSize.min,
            children: list,
          ),
        ),
        gravity: gravity ?? ToastGravity.BOTTOM,
        toastDuration: const Duration(seconds: 2));
  }
}
